package com.zyb.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zyb.request.SysUserRequest;
import com.zyb.services.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import com.zyb.model.po.SysUser;


@Controller
@RequestMapping("/sysUser")
public class SysUserController {

    @Autowired
    private SysUserService sysUserService;


    @GetMapping(value = "test")
    @ResponseBody
    public String test(){
        //测试逻辑删除功能
        SysUser sysUser = sysUserService.selectById("bdf2566136c746b4be57c955422eb529");

        //测试分页
        QueryWrapper<SysUser> objectQueryWrapper = new QueryWrapper<>();
        IPage<SysUser> sysUserIPage = sysUserService.selectPage(new Page<SysUser>(1, 10), new QueryWrapper<>());

        //测试公共字段自动填充
        SysUser sysUser1 = new SysUser();
        sysUser1.setUsername("张三");

        sysUserService.insert(sysUser1);


        SysUser sysUser2 = new SysUser();
        sysUser2.setId("bdf2566136c746b4be57c955422eb529");
        sysUser2.setUsername("李四");


        sysUserService.updateById(sysUser2);

        return "ok";
    }

    @GetMapping(value = "page")
    @ResponseBody
    public IPage<SysUser> getPage(SysUserRequest request){
        request.setUsername("张三");
        IPage<SysUser> page =   sysUserService.getPage(request);
        return page;
    }

}

